/**页面视图插件*/
(function($) {
	/**注册页面*/
	$.fn.registerQuickView = function(config)
	{
		$(".quick-btn").QuickBtn();
		$(".quick-form").QuickForm();
		$(".quick-datagrid").QuickDatagrid();
		/**处理按钮事件 兼容动态添加的元素*/
		$(this).on("click", ".quick-btn", function(){
			$(this).QuickBtn("proxyClick");
		});
		
		if(config)
		{
			var endFunc = config["endFunction"];
			if(endFunc)
			{
				endFunc();
			}
		}
	}
})(jQuery);

/**URL工具类*/
(function ($) {
	var host = window.location.host;
	var pathName = window.document.location.pathname;
	var projectName = pathName.substring(0, pathName.substr(1).indexOf('/')+1);
	var currPagePath = pathName.substring(0, pathName.substr(1).lastIndexOf('/')+1) 
	$.QuickUrlUtils = {
		redirectUrl: function(url)
		{
			location = currPagePath + "/" + url;
		},
		redirectRootUrl: function(url)
		{
			location = projectName + "/" + url;
		}
		,getProjectName: function()
		{
			return projectName;
		}
		,geCurrPagePath: function()
		{
			return currPagePath;
		}
		,getHost: function(){
			return host;
		}
		,getHostProject: function(){
			return host + projectName;
		}
		,forward: function(url, title, subTitle,isClose)
		{
			StoreCache.setCache("title",title);
			if($.QuickVersion["isWeb"])
			{
				location = url;
			}
			else if($.QuickVersion["isWeixin"])
			{
				location = url;
			}
			else if($.QuickVersion["android"])
			{
				if(!isClose) isClose = "2";
				var tzurl =currPagePath+"/"+url;
				if(url.indexOf("FJZLYD")!=-1){
					tzurl = url;
				}
				android.toWebViewActivity(tzurl, title, "",isClose);
			}
			else if($.QuickVersion["iPhone"])
			{
				window.webkit.messageHandlers.fjzlyd.postMessage({functionName:"toWebViewActivity",parameter:{url: currPagePath+"/"+url, title: title, subTitle: "", isClose: isClose }});
			} 
		}
		,forwardRootUrl: function(url, title, subTitle,isClose)
		{
			if($.QuickVersion["isWeb"])
			{
				location = projectName+"/"+url;
			}
			else if($.QuickVersion["isWeixin"])
			{
				location = projectName+"/"+url;
			}
			else if($.QuickVersion["android"])
			{
				if(!isClose) isClose = "2";
				android.closeAllWebView(projectName+"/"+url, title, "",isClose);
			}
			else if($.QuickVersion["iPhone"])
			{
				window.webkit.messageHandlers.fjzlyd.postMessage({functionName:"toWebViewActivity",parameter:{url: projectName+"/"+url, title: title, subTitle: "", isClose: isClose }});
			} 
		}
		,forwardAny: function(url)
		{
			location = url;
		}
		,openNewWindow: function(url, title)
		{
			window.open(url);
		}
		//获取URL参数  
		,getRequest: function(key) {
			var url = decodeURI(location.search); //获取url中"?"符后的字串  
			var theRequest = new Object();
			if (url.indexOf("?") != -1) {
				var str = url.substring(url.indexOf("?")+1, url.length);
				strs = str.split("&");
				for (var i = 0; i < strs.length; i++) {
					if(!StringUtils.isEmpty(strs[i]))
					theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
				}
			}
			if (!key)
				return theRequest;
			else
				return theRequest[key];
		}
		//获取URL参数  
		,getRequestByURL: function(url, key) {
			var theRequest = new Object();
			if (url.indexOf("?") != -1) {
				var str = url.substring(url.indexOf("?")+1, url.length);
				strs = str.split("&");
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
				}
			}
			if (key == "")
				return theRequest;
			else
				return theRequest[key];
		}
		/**退回上级页面*/
		,back: function(){
			history.back(-1);
		}
	};
})(jQuery);

/**视图工具类*/
(function($) {
	var defaultConfig = {
		needNull: false
		,textField: "XMMC"
		,valueField: "XMDM"
	};
	$.fn.createOptions = function(ary, config)
	{
		var finalConfig = $.extend({}, defaultConfig, config);
		$(this).empty();
		var needNull = finalConfig["needNull"];
		var textField = finalConfig["textField"];
		var valueField = finalConfig["valueField"];
		
		var opts = [];
		
		if(needNull == "true")
		{
			var opt = $('<option>');
			opt.attr("value", "");
			opt.text("请选择");
			//opt.css("display", "none");
			opts.push(opt);
		}
		for(var i=0; i<ary.length; i++)
		{
		    var item = ary[i];
		    var value = item[valueField];
			var text = item[textField];
			var option = $('<option>');
			$(option).attr('value', value);
			$(option).html(text);
			$(option).data(item);
			var children = item['children'];
			if(!StringUtils.isEmpty(children))
			{
				$(option).attr("children", JSON.stringify(children));
			}
			opts.push(option);
			//options += $(option)[0].outerHTML;
		}
		$(this).append(opts);
	}
})(jQuery);










